/*
 * Copyright (c) 2015. For Intelligent Group.
 */
package com.intelligent.ispc.client.core.modal.grr;

import com.intelligent.ispc.common.utils.StringUtils;
import com.intelligent.ispc.core.dto.GrrConfigDto;

/**
 * Created by cherry on 16/9/10.
 */
public class ConfigModel {

    private int partCount;
    private int appraiserCount;
    private int trialCount;
    private String schema;
    private double[] rules;
    private String sigma;

    /**
     * ConfigModel constructor
     */
    public ConfigModel() {

    }

    /**
     * set configModel data source
     *
     * @param grrConfig grrConfig data source
     */
    public void setData(GrrConfigDto grrConfig) {

        if (grrConfig == null) {
            return;
        }

        schema = grrConfig.getScheme();
        sigma = grrConfig.getSigma();

        String rule = grrConfig.getRule();
        String modelValue = grrConfig.getModelValue();

        if (modelValue.length() > 1) {

            String[] modelValues = modelValue.substring(1, modelValue.length() - 1).split(",");
            partCount = Integer.parseInt(modelValues[0]);
            appraiserCount = Integer.parseInt(modelValues[1]);
            trialCount = Integer.parseInt(modelValues[2]);

        }

        if (rule.length() > 1) {
            String[] grrRules = rule.substring(1, rule.length() - 1).split(",");
            if (grrRules == null || grrRules.length == 0) {
                return;
            }

            rules = new double[grrRules.length];
            for (int i = 0; i < grrRules.length; i++) {
                if (StringUtils.isNumeric(grrRules[i])) {
                    rules[i] = Double.parseDouble(grrRules[i]);
                }
            }
        }
    }

    public int getPartCount() {
        return partCount;
    }

    public int getAppraiserCount() {
        return appraiserCount;
    }

    public int getTrialCount() {
        return trialCount;
    }

    public String getSchema() {
        return schema;
    }

    /**
     * @return grr rules
     */
    public double[] getRules() {
        double[] newRules = rules;
        return newRules;
    }

    /**
     * @return grr config sigma
     */
    public String getSigma() {
        return sigma;
    }
}
